<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            margin: 100px auto;
            width: 300px;
            height: 340px;
            border: 1px solid #000;
        }
        .top{
            font-size: 0;
            border-bottom: 1px solid #000;
        }
        .top button{
            font-size: 18px;
            width: 60px;
            height: 40px;
            border: none;
            outline: none;
        }
        .top button.selected{
            background-color: green;
        }
        .bottom div{
            display: none;
            background-color: gold;
            line-height: 300px;
            text-align: center;
        }
        .bottom div.selected{
            display: block;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="top">
            <button class="selected">按钮1</button>
            <button>按钮2</button>
            <button>按钮3</button>
            <button>按钮4</button>
            <button>按钮5</button>
        </div>
        <div class="bottom">
            <div class="selected">盒子1</div>
            <div>盒子2</div>
            <div>盒子3</div>
            <div>盒子4</div>
            <div>盒子5</div>
        </div>
    </div>
</body>
</html>
<script>
    window.onload = function(){
        var btn = document.querySelectorAll("button")
        var bod = document.querySelectorAll(".bottom>div")
        btn.forEach((item,index)=>{
            item.onclick = function(){
                btn.forEach((item,index)=>{
                    item.className = ''
                    bod[index].className = ''
                })
                item.className = 'selected'
                bod[index].className = 'selected'
            }
        })
    }
</script>